package com.etc.cloud;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;

/**
 * @Author kalista
 * @Description
 * @Date 2020/8/23  10:41
 **/
@EnableCircuitBreaker
@EnableEurekaClient
@SpringBootApplication
@Slf4j
public class PaymentHystrixMain8001 {
    public static void main(String[] args) {
        SpringApplication.run( PaymentHystrixMain8001.class,args);
        log.info("****************PaymentHystrixMain8001 启动 ************ ");
    }


    /**
     * 此配置是为了服务监控而配置。 与服务容错没有关系。 springcloud升级的一个炕
     * 只要在自己的项目中配置下面的servlet即可
     * @return
     */
    @Bean
    public ServletRegistrationBean getServlet(){
        HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
        ServletRegistrationBean<HystrixMetricsStreamServlet> registrationBean = new ServletRegistrationBean<>(streamServlet);
        registrationBean.setLoadOnStartup(1);
        registrationBean.addUrlMappings("/hystrix.stream");
        registrationBean.setName("HystrixMetricsStreamServlet");
        return registrationBean;
    }


}
